(function () {
    "use strict";

    // I know it's a buggy solution, but for the homework is fine, I guess
    var correctInput;
    var textField = document.getElementById('onlyNumbers');
    textField.addEventListener('keyup', function () {
        var input = textField.value;

        if (isNumber(input[input.length - 1])) {
            correctInput = input;
        }
        else {
            var currentColor = textField.style.backgroundColor;
            textField.style.backgroundColor = 'red';
            textField.value = correctInput;

            setTimeout(function () {
                textField.style.backgroundColor = currentColor;
            }, 300);
        }
    });

    function isNumber(n) {
        return !isNaN(parseFloat(n)) && isFinite(n);
    }
}());